﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Scoreboard.Interfaces;
using Scoreboard.Model;
using System.Collections.Generic;
using System.ServiceModel.DomainServices.Client;
using Scoreboard.Basement;
using Scoreboard.Basement.ViewModels;

namespace Scoreboard.Home
{
	public class ViewModel : PageViewModel
	{
		private ITournamentRepository _tournamentRepository;

		private IEnumerable<Tournament> _currentTournaments;

		public ViewModel()
		{
			_tournamentRepository = ServiceLocator.Get<ITournamentRepository>();

			AddUpdater(EntityTypes.Tournaments, LoadTournaments);
		}

		protected override string Name
		{
			get
			{
				return "Home";
			}
		}

		public IEnumerable<Tournament> CurrentTournaments
		{
			get
			{
				if (_currentTournaments == null)
				{
					LoadTournaments();
				}
				return _currentTournaments;
			}
			set
			{
				_currentTournaments = value;
				FirePropertyChanged("CurrentTournaments");
			}
		}		

		private void LoadTournaments()
		{
			//_tournamentRepository.GetCurrentTournaments(LoadTournamentsCompleted);
		}

		private void LoadTournamentsCompleted(LoadOperation<Tournament> operation)
		{
			CurrentTournaments = operation.Entities;
		}
	}
}
